<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title><?php echo C('APP_NAME');?>管理后台</title>
    <link rel="stylesheet" href="/Public/layui/css/layui.css">
    <script type="text/javascript" src="/Public/layui/layui.js"></script>
    <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    
</head>
<body>
<div style="margin: 15px;">
    
    <fieldset class="layui-elem-field">
        <legend>订单管理 - <?php echo (isset($detail['id'])?'编辑':'新增');?>订单</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <?php if(isset($detail['id'])): ?><input type="hidden" name="id" value="<?php echo ($detail['id']); ?>"><?php endif; ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 代理</label>
                    <div class="layui-input-block">
                        <select name="expressName" lay-verify="required">
                            <option value="0">快递公司</option>
                            <?php if(is_array($express)): $i = 0; $__LIST__ = $express;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($key); ?>" <?php echo ($detail['expressName'] == $key?'selected':'');?>><?php echo ($vo); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 快递单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="expressNumber" required value="<?php echo (isset($detail['expressNumber'])?$detail['expressNumber']:'');?>" lay-verify="required" placeholder="快递单号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 快递路由</label>
                    <div class="layui-input-block">
                        <input type="text" name="expressLog" required value="<?php echo (isset($detail['expressLog'])?$detail['expressLog']:'');?>"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>

</div>

    <script>
        layui.use('form', function(){
            var form = layui.form();
            form.on('submit(admin-form)', function(data){
                $.ajax({
                    type: "POST",
                    url: '<?php echo U("put");?>',
                    data: data.field,
                    success: function(msg){
                        if( msg.code == 1 ){
                            parent.location.reload();
                        }else{
                            parent.layer.msg(msg.msg, {
                                icon: 5,
                                shade: [0.6, '#393D49'],
                                time:1500
                            });
                        }
                    }
                });
                return false;
            });

        });
    </script>
    <script>
        layui.use('form', function(){
            //如果有需要到镇的改改就可以实现
            var form = layui.form(),
                    layer = layui.layer,
                    $ = layui.jquery;
            var url =  '<?php echo U("getArea");?>'; //数据请求地址
            var province = "广东省"; //编辑需要的省
            var city = "广州市"; //编辑需要的市
            var district = "天河区"; //编辑需要的县/区
            getJSON(url,$("select[name='province']").closest("div"));
            form.on('select(state)', function(data){
                $that = $(data.elem);
                urls = url+"&id="+data.value;
                getJSON(urls,$that.closest("div").next());
            });
            function getJSON(urls,even){
                $.getJSON(urls, function(json){
                    var pid = 0;
                    var name = even.find("select").attr("name");
                    var select = "<select name=\"" + name + "\" lay-filter=\"state\">";
                    select += "<option value=\"0\">请选择 </option>";
                    $(json).each(function(){
                        select += "<option value=\"" + this.id + "\"";
                        if(province == this.value || city == this.value || district == this.value){
                            select += " selected=\"selected\" ";
                            pid = this.id;
                        }
                        select += ">" + this.value + "</option>";
                    });
                    select += "</select>";
                    even.html(select);
                    var nextName = even.next().find("select").attr("name");
                    even.next().html("<select name=\"" + nextName + "\" lay-filter=\"state\"><option value=\"0\">请选择 </option></select>");
                    form.render('select');
                    if(pid != 0){
                        getJSON(url+"?id="+pid,even.next());
                    }
                });
            }
        });
    </script>

</body>
</html>